package common;

public class Token {
	
	private static String[] typeName = new String[46];
	{
		typeName[0] = "INTEGER_NUMBER";
		typeName[1] = "REAL_NUMBER";
		typeName[2] = "RATIONAL_NUMBER";
		typeName[3] = "ID";
		typeName[4] = "BEGIN";
		typeName[5] = "END";
		typeName[6] = "IF";
		typeName[7] = "THEN";
		typeName[8] = "ELSE";
		typeName[9] = "READ";
		typeName[10] = "WRITE";
		typeName[11] = "GOTO";
		typeName[12] = "LABEL";
		typeName[13] = "LT";
		typeName[14] = "GT";
		typeName[15] = "EQ";
		typeName[16] = "NEQ";
		typeName[17] = "LTE";
		typeName[18] = "GTE";
		typeName[19] = "AND";
		typeName[20] = "NOT";
		typeName[21] = "OR";
		typeName[22] = "PLUS";
		typeName[23] = "MINUS";
		typeName[24] = "MULT";
		typeName[25] = "DIV";
		typeName[26] = "SEMICOLON";
		typeName[27] = "VAR";
		typeName[28] = "TO";
		typeName[29] = "DOWNTO";
		typeName[30] = "INTEGER";
		typeName[31] = "REAL";
		typeName[32] = "TYPE";
		typeName[33] = "RATIONAL";
		typeName[34] = "PROGRAM";
		typeName[35] = "LPAREN";
		typeName[36] = "RPAREN";
		typeName[37] = "LBRACK";
		typeName[38] = "RBRACK";
		typeName[39] = "COLON";
		typeName[40] = "EOF";
		typeName[41] = "COMMA";
		typeName[42] = "PERIOD";
		typeName[43] = "CONST";		
		typeName[44] = "DO";		
		typeName[45] = "ASSIGN";
	}
	public final static int INTEGER_NUMBER = 0;
	public final static int REAL_NUMBER = 1;
	public final static int FRACTIONAL_NUMBER = 2;
	public final static int ID = 3;
	public final static int BEGIN = 4;
	public final static int END = 5;
	public final static int IF = 6;
	public final static int THEN = 7;
	public final static int ELSE = 8;
	public final static int READ = 9;
	public final static int WRITE = 10;
	public final static int GOTO = 11;
	public final static int LABEL = 12;
	public final static int LT = 13;
	public final static int GT = 14;
	public final static int EQ = 15;
	public final static int NEQ = 16;
	public final static int LTE = 17;
	public final static int GTE = 18;
	public final static int AND = 19;
	public final static int NOT = 20;
	public final static int OR = 21;
	public final static int PLUS = 22;
	public final static int MINUS = 23;
	public final static int MULT = 24;
	public final static int DIV = 25;
	public final static int SEMICOLON = 26;
	public final static int VAR = 27;
	public final static int TO = 28;
	public final static int DOWNTO = 29;
	public final static int INTEGER = 30;
	public final static int REAL = 31;
	public final static int TYPE = 32;
	public final static int RATIONAL = 33;
	public final static int PROGRAM = 34;
	public final static int LPAREN = 35;
	public final static int RPAREN = 36;
	public final static int LBRACK = 37;
	public final static int RBRACK = 38;
	public final static int COLON = 39;
	public final static int EOF = 40;
	public final static int COMMA = 41;
	public final static int PERIOD = 42;
	public final static int CONST = 43;
	public final static int DO = 44;
	public final static int ASSIGN = 45;

	private int type;
	private Number value;
	private String idName;
		
	public Token(int type, String idName) {
		this.type = type;
		this.idName = idName;
	}
	
	public Token(int type, Number value) {
		this.type = type;
		this.value = value;
	}

	public Token(int type) {
		this.type = type;
	}

	public String toString() {
		String res = typeName[type];
		if (value != null) {
			res += " (" + value + ")";
		}
		if (idName != null) {
			res += " (" + idName + ")"; 
		}
		return res;
	}
	
	public boolean isEOF() {
		return this.type == EOF;
	}
	
}

